package com.flnet.spsys.controller;


import com.flnet.spsys.annotation.Me;
import com.flnet.spsys.entity.CurrentUser;
import com.flnet.spsys.entity.TbAuthor;
import com.flnet.spsys.service.ITbAuthorService;
import com.flnet.spsys.utils.ResultJson;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.flnet.spsys.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 策划师作者信息 前端控制器
 * </p>
 *
 * @author Qu Jingbin
 * @since 2021-03-16
 */
@RestController//@ResponseBody和@Controller的组合注解
@RequestMapping("/author")
public class TbAuthorController extends BaseController {
    @Autowired
    ITbAuthorService authorService;

    @ApiOperation(value = "作者设置", notes = "作者设置")
    @ApiResponses(
            @ApiResponse(code = 200, message = "操作成功", response = ResultJson.class)
    )
    @ResponseBody
    @PostMapping(value = "/info/me")
    //跨域
    @CrossOrigin
    public Object getAuthorInfo(@Me CurrentUser currentUser) {
        List<TbAuthor> userList = authorService.list();
//        for(User user:userList) {
//            System.out.println(user);
//        }
//
//        currentUser.setId(1);
//        authorService.getById(1);

        return ResultJson.success(userList);
    }

/*
    @ApiOperation(value = "作者设置", notes = "作者设置")
    @ApiResponses(
            @ApiResponse(code = 200, message = "操作成功", response = ResultJson.class)
    )
    @ResponseBody
    @PostMapping(value = "/info")
    @CrossOrigin
    public Object getAuthorInfo(@RequestBody UserLoginVO userLoginVO) {
        String username = userLoginVO.getUsername();
        String password = userLoginVO.getPasswd();

        User user = userService.selectByName(username);
        if (user == null) {
            return ResultJson.failure("该用户未注册",null);
        }
        if (!password.equals("123456")) {
            return ResultJson.failure("密码错误,请重新输入",null);
        }
//        if (!user.getPasswd().equals(Md5Util.MD5(passwd) + username)) {
//            return ResultJson.failure("密码错误,请重新输入",null);
//        }
        //session.setAttribute("loginUser", user);
        return ResultJson.success(null);
    }*/
}
